package online.hxstart.code.concurrent.chapter05;

import java.util.concurrent.TimeUnit;

/**
 * @author huxing
 * @date 19-4-24 星期三 下午2:13
 * @describe
 */
public class SynchronizedDefect {

  public synchronized void syncMethod() {
    try {
      System.out.println(Thread.currentThread());
      TimeUnit.MILLISECONDS.sleep(5);
      System.out.println(Thread.interrupted());
    } catch (InterruptedException e) {
      e.printStackTrace();
      System.out.println("eeeeeeeeeeeeeee"+Thread.interrupted());
    }
  }

  public static void main(String[] args) throws InterruptedException {
    SynchronizedDefect defect = new SynchronizedDefect();
    Thread thread = new Thread(defect::syncMethod, "thread-0");
    thread.start();
    TimeUnit.MILLISECONDS.sleep(2);
    Thread thread1 = new Thread(defect::syncMethod, "thread-1");
    thread1.start();
    TimeUnit.MILLISECONDS.sleep(2);

    thread1.interrupt();

//    System.out.println(thread1.isInterrupted());
//    System.out.println(thread1.getState());
  }
}
